<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <a id="box" href="https://www.baidu.com">This is a DIV</a>
    <script>
        var boxObj = document.getElementById('box');
        // boxObj.setAttribute('onclick', 'warning();');
        boxObj.addEventListener('click',function(e){ 
            // console.log(e);
            warning(e);
        }, false);
        function warning(event){
            console.log(event.cancelable);
            // console.log(event);
            event.preventDefault();
        }
        var e = new Event('click');
        console.log(e.cancelable);
        console.log(e);
        var c = boxObj.dispatchEvent(e);
        console.log(e);

    </script>
</body>
</html>